<?php

/*

  Action - Attack	$3

  +$2
  Each other player trashes the top card of his deck and gains a card with the same cost that you choose.

 */

class Swindler extends Card implements iAction, iKingdom, iAttack, iIntrigue {

    public function __construct() {
        parent::__construct("Swindler", 3);
        $this->undoPlay = false;
        $this->undoBuy = true;
    }

    public function getDescription() {
        return array(
            "+$2",
            "Each other player trashes the top card of his deck and gains a card with the same cost that you choose.");
    }
    
    private function helper(Game $game, $name) {
        $card = $game->removeCardFromDrawDeck($name);
        if ($card) {
             ScreenDisplay::addScreenMessage($game, true, "trash ". nicePrint($card), "trashes ".ScreenDisplay::$LMSG, $name);
            $game->putCardInTrash($card);
            $price = $card->getPrice($game);
            $optional_cards = $game->getBoardCardsByPrice($price, $price);
            if (sizeof($optional_cards) > 0) {
                
                $output = MySocket::GetUserReply($game,  Input_ChooseOne, $optional_cards, 1, 1, null, "Choose a new card for" . $name);
                $card_name = $output[0];
                $card = $game->moveCardFromPileToPile($card_name, BoardCards, DiscardPile, $name);
                 ScreenDisplay::addScreenMessage($game, false, " and gain ". nicePrint($card), " and gains ".ScreenDisplay::$LMSG, $name);
            }
        }
    }

    public function play(Game $game, $isRealCard) {
        $game->addMoney(2);
         ScreenDisplay::addScreenMessage($game, true, "get +2$", "gets +2$");
        $game->setPhase(Phase_Sleep);
        
        $game->attack($this);
        
        $names = $game->getOtherPlayersNames(true);
        foreach($names as $name) {
                $this->helper($game, $name);
        }
        $game->cardActionFinished();
        return true;
    }
}

?>